﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using ERP_RORZE_DLL.Product.DAO;
using ERP_RORZE_DLL.Product.database;
using ERP_RORZE_DLL.Product.Base;

namespace ERP_RORZE.Product.PartData
{
    public partial class Frm_PartMaterialEdit : DevExpress.XtraEditors.XtraForm
    {
        ClsPartDataTable obj = new ClsPartDataTable();
        ClsPartDataDAO clspartDAO = new ClsPartDataDAO();
        DataTable dt;
        public EventHandler Re_Load;

        public string ID;
        public string InputDate;
        public string PartID;
        public string MaterialID;
        public string MaterialType;
        public string Workpiecesize;
        public string shape;
        public string Thickness;
        public string width;
        public string lenght;
        public string Cut;
        public  string RawMachine ;
        public string HandFinish;
        public string HairLine;
        public string WAnod;
        public string BAnod;
        public string Blast30;
        public string Blast60;
        public string Seal;
        public string Migaki;
        public string Bafu;
        public string Cleanwave;
        public string VacPac;
        public string Helisert;
        public string SerialNo;
        public string PalCoat;
        public string Otherpro;
        public string Price;
        public string Memo;
        public string Note;
        public string Caciras;
        public string Inside;

        public Frm_PartMaterialEdit()
        {
            InitializeComponent();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Frm_PartMaterialEdit_Load(object sender, EventArgs e)
        {
            // lấy danh sách PartID truyền vào cbPartID
            dt = clspartDAO.GetAllPartID();
            cbPartID.DataSource = dt;
            cbPartID.DisplayMember = "PartNo";
            cbPartID.ValueMember = "PartNo";

            //Lấy danh sách MaterialID truyền vào cbMaterialID
            dt = clspartDAO.MaterialID();
            cbMaterialID.DataSource = dt;
            cbMaterialID.DisplayMember = "MaterialID";
            cbMaterialID.ValueMember = "MaterialID";

            // lấy các giá trị điền vào các hộp text để sửa
             dateInputDate.Value = DateTime.Parse(InputDate);
             cbPartID.Text =PartID;
             cbMaterialID.Text = MaterialID;
             txtLenght.Text = lenght;
             txtMaterialType.Text = MaterialType;
             txtMemo.Text = Memo;
             txtNote.Text =Note;
             txtOtherpro.Text = Otherpro;
             txtPrice.Text = Price;
             txtShape.Text = shape;
             txtThickness.Text = Thickness;
             txtWidth.Text = width;
             txtWorkpiecesize.Text = Workpiecesize;
             checkBafu.Checked = bool.Parse(Bafu);
             checkBAnod.Checked = bool.Parse(BAnod);
             checkBlast30.Checked = bool.Parse(Blast30);
             checkBlast60.Checked = bool.Parse(Blast60);
             checkCaciras.Checked = bool.Parse(Caciras);
             checkCleanwave.Checked = bool.Parse(Cleanwave);
             checkCut.Checked = bool.Parse(Cut);
             checkHairLine.Checked = bool.Parse(HairLine);
             checkHandFinish.Checked  = bool.Parse(HandFinish);
             checkHelisert.Checked = bool.Parse(Helisert);
             checkInside.Checked = bool.Parse(Inside);
             checkMigaki.Checked =bool.Parse(Migaki);
             checkPalCoat.Checked = bool.Parse(PalCoat);
             checkRawMachine.Checked = bool.Parse(RawMachine);
             checkSeal.Checked = bool.Parse(Seal);
             checkSeriaNo.Checked = bool.Parse(SerialNo);
             checkVacPac.Checked = bool.Parse(VacPac);
             checkWAnod.Checked = bool.Parse(WAnod);
        }

        void ThongBao(string name)
        {
            MessageBox.Show("Chưa nhập " + name + ". Vui lòng nhập lại");
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            if (txtLenght.Text == "")
            {
                ThongBao(clsConstantsdb.Entities.ClsDBPartData.FieldName.lenght);
            }
            else if (txtMaterialType.Text == "")
            {
                ThongBao(clsConstantsdb.Entities.ClsDBPartData.FieldName.MaterialType);
            }
            else if (txtMemo.Text == "")
            {
                ThongBao(clsConstantsdb.Entities.ClsDBPartData.FieldName.Memo);
            }
            else if (txtNote.Text == "")
            {
                ThongBao(clsConstantsdb.Entities.ClsDBPartData.FieldName.Note);
            }
            else if (txtOtherpro.Text == "")
            {
                ThongBao(clsConstantsdb.Entities.ClsDBPartData.FieldName.Otherpro);
            }
            else if (txtPrice.Text == "")
            {
                ThongBao(clsConstantsdb.Entities.ClsDBPartData.FieldName.Price);
            }
            else if (txtShape.Text == "")
            {
                ThongBao(clsConstantsdb.Entities.ClsDBPartData.FieldName.shape);
            }
            else if (txtThickness.Text == "")
            {
                ThongBao(clsConstantsdb.Entities.ClsDBPartData.FieldName.Thickness);
            }
            else if (txtWidth.Text == "")
            {
                ThongBao(clsConstantsdb.Entities.ClsDBPartData.FieldName.width);
            }
            else if (txtWorkpiecesize.Text == "")
            {
                ThongBao(clsConstantsdb.Entities.ClsDBPartData.FieldName.Workpiecesize);
            }
            else
            {
                obj.InputDate = dateInputDate.Value;
                obj.PartID = cbPartID.Text;
                obj.MaterialID = cbMaterialID.Text;
                obj.Lenght = float.Parse(txtLenght.Text);
                obj.MaterialType = txtMaterialType.Text;
                obj.Memo = txtMemo.Text;
                obj.Note = txtNote.Text;
                obj.Otherpro = txtOtherpro.Text;
                obj.Price = int.Parse(txtPrice.Text);
                obj.Shape = txtShape.Text;
                obj.Thickness = float.Parse(txtThickness.Text);
                obj.Width = float.Parse(txtWidth.Text);
                obj.Workpiecesize = txtWorkpiecesize.Text;
                obj.Bafu = checkBafu.Checked;
                obj.BAnod = checkBAnod.Checked;
                obj.Blast30 = checkBlast30.Checked;
                obj.Blast60 = checkBlast60.Checked;
                obj.Caciras = checkCaciras.Checked;
                obj.Cleanwave = checkCleanwave.Checked;
                obj.Cut = checkCut.Checked;
                obj.HairLine = checkHairLine.Checked;
                obj.HandFinish = checkHandFinish.Checked;
                obj.Helisert = checkHelisert.Checked;
                obj.Inside = checkInside.Checked;
                obj.Migaki = checkMigaki.Checked;
                obj.PalCoat = checkPalCoat.Checked;
                obj.RawMachine = checkRawMachine.Checked;
                obj.Seal = checkSeal.Checked;
                obj.SerialNo = checkSeriaNo.Checked;
                obj.VacPac = checkVacPac.Checked;
                obj.WAnod = checkWAnod.Checked;
                obj.ID = int.Parse(ID);
                clspartDAO.UpdatePartMaterial(obj);
                this.Re_Load(sender, e);
            }
        }
    }
}